%% Actual outcomes, all
clear
load Matlab_2014_12_cluster.mat

TOTobs  = size(st_dataset,1);
Nobs    = zeros(TOTobs,1);

for i=0:50
    Ntemp = single(st_dataset(:,i+7));
    Nobs  = Nobs+i*Ntemp;
end

PartProb = single(st_dataset(:,3));

1314-sum(PartProb)
sum(Nobs==0) - (1314-sum(PartProb)) % Number planting 0 but taking up
sum(Nobs<35) - sum(Nobs==0) %planting between 1 and 34
sum(Nobs==35)
sum(Nobs>35) - sum(Nobs==50) %planting between 36 and 49
sum(Nobs==50)


%% Actual outcomes, fully subsidized takeup
clear
load Matlab_2014_12_cluster.mat

TOTobs  = size(st_dataset,1);
Nobs    = zeros(TOTobs,1);

for i=0:50
    Ntemp = single(st_dataset(:,i+7));
    Nobs  = Nobs+i*Ntemp;
end

obsdata = [single(st_dataset(:,1)),single(st_dataset(:,2)),single(st_dataset(:,3)),Nobs];
clearvars PartProb Nobs

obsdata(obsdata(:,1)~=12,:)=[];

PartProb = obsdata(:,3);
Nobs     = obsdata(:,4);

TOTobs = size(obsdata,1)

TOTobs-sum(PartProb)
sum(Nobs==0) - (TOTobs-sum(PartProb)) % Number planting 0 but taking up
sum(Nobs<35) - sum(Nobs==0) %planting between 1 and 34
sum(Nobs==35)
sum(Nobs>35) - sum(Nobs==50) %planting between 36 and 49
sum(Nobs==50)

%% Actual outcomes, just strictly positive takeup cost
clear
load Matlab_2014_12_cluster.mat

TOTobs  = size(st_dataset,1);
Nobs    = zeros(TOTobs,1);

for i=0:50
    Ntemp = single(st_dataset(:,i+7));
    Nobs  = Nobs+i*Ntemp;
end

obsdata = [single(st_dataset(:,1)),single(st_dataset(:,2)),single(st_dataset(:,3)),Nobs];
clearvars PartProb Nobs

obsdata(obsdata(:,1)==12,:)=[];

PartProb = obsdata(:,3);
Nobs     = obsdata(:,4);

TOTobs = size(obsdata,1)

TOTobs-sum(PartProb)
sum(Nobs==0) - (TOTobs-sum(PartProb)) % Number planting 0 but taking up
sum(Nobs<35) - sum(Nobs==0) %planting between 1 and 34
sum(Nobs==35)
sum(Nobs>35) - sum(Nobs==50) %planting between 36 and 49
sum(Nobs==50)

%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% simdata.mat was as created with
%
% [PartProb,Npdf,Nobs,Prof1,Prof0,EN,OV,Prof0_C] = Full_Simulate(coefftran(theta_hat2,0),DP,A,R,TG,MON,snPass,rp);
%
% load('Matlab_2014_12_cluster.mat')
% group = st_dataset(:,58);
% group = double(group);
% 
% simdata=[A,R,PartProb,Nobs,Prof0,Prof1,TG,MON,group];
% 
% save 'zambia_simdata.mat' 'simdata'
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%% Predicted outcomes (all observations)
clear
load zambia_simdata.mat

PartProb = simdata(:,3);
Nobs     = simdata(:,4);

1314-sum(PartProb)
sum(Nobs==0) - (1314-sum(PartProb)) % Number planting 0 but taking up
sum(Nobs<35) - sum(Nobs==0) %planting between 1 and 34
sum(Nobs==35)
sum(Nobs>35) - sum(Nobs==50) %planting between 36 and 49
sum(Nobs==50)

%% Now fully subsidized takeup
clear 
load zambia_simdata.mat
% Remove data
simdata(simdata(:,1)~=12,:)=[];

PartProb = simdata(:,3);
Nobs     = simdata(:,4);

TOTobs = size(simdata,1)

TOTobs-sum(PartProb)
sum(Nobs==0) - (TOTobs-sum(PartProb)) % Number planting 0 but taking up
sum(Nobs<35) - sum(Nobs==0) %planting between 1 and 34
sum(Nobs==35)
sum(Nobs>35) - sum(Nobs==50) %planting between 36 and 49
sum(Nobs==50)

%% Now just strictly positive takeup cost
clear 
load zambia_simdata.mat
% Remove data
simdata(simdata(:,1)==12,:)=[];

PartProb = simdata(:,3);
Nobs     = simdata(:,4);

TOTobs = size(simdata,1)

TOTobs-sum(PartProb)
sum(Nobs==0) - (TOTobs-sum(PartProb)) % Number planting 0 but taking up
sum(Nobs<35) - sum(Nobs==0) %planting between 1 and 34
sum(Nobs==35)
sum(Nobs>35) - sum(Nobs==50) %planting between 36 and 49
sum(Nobs==50)